#-*-coding:utf-8 -*-
from django import template
import datetime
import re

register = template.Library()

@register.filter(name='source')
def source(value):
    source = {1:'app',2:'backend'}
    return source.get(value, 'unknown') 



@register.filter(name='dy')
def dy(value):
   a_class = {0:'商品',1:'分店',2:'活动'}
   return a_class.get(value, 'unknown') 

import time
@register.filter(name='strftime')
def strftime(value, arg):
   start_time = time.strftime(arg,time.localtime(value))
   return  start_time 

@register.tag(name="current_time")
def do_current_time(parser, token):
    try:
        # split_contents() knows not to split quoted strings.
        tag_name, format_string = token.split_contents()
    except ValueError:
        msg = '%r tag requires a single argument' % token.split_contents()[0]
        raise template.TemplateSyntaxError(msg)
    return CurrentTimeNode(format_string[1:-1])



